require('http').createServer(function (req, res) {
    function print(){
        res.writeHead(200,{'Content-Type':'text/plain'});
        res.end(JSON.stringify({
            url:req.url,
            method:req.method,
            headers:req.headers
        }));
    }

    switch(req.url){
        case '/redirect':
            res.writeHead(301,{Location:'/'});
            res.end();
            break;

        case '/body':
            req.setEncoding('utf8');
            var body='';
            req.on('data', function (chunk) {
                body+=chunk;
            });
            req.on('end', function () {
                res.end(JSON.stringify(body));
            });
            break;

        default :
            print();
            break;
    }
}).listen(4000, function () {
    console.log('port 4000 - ',new Date());
});
